package guiHandler;

/**
 * 
 * @author Peter Steiner & Fredrik Wallenius
 *
 */
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import javax.swing.*;

/**
 * EastPanel.java
 * 
 * Fredrik Wallenius and Peter Steiner 
 * DP08 - KTH - 2009
 *
 */
public class EastPanel extends JPanel  {
	
	private JTextArea textArea;
	private final static String newline = "\n";
	
	public EastPanel(){
		super(new GridBagLayout());
	        
	        textArea = new JTextArea(20,20);
	        textArea.setEditable(false);
	        JScrollPane scrollPane = new JScrollPane(textArea);

	        //Add Components to this panel.
	        GridBagConstraints c = new GridBagConstraints();
	        c.gridwidth = GridBagConstraints.REMAINDER;

	        c.fill = GridBagConstraints.BOTH;
	        c.weightx = 1.0;
	        c.weighty = 1.0;
	        add(scrollPane, c);
	        
	        c.fill = GridBagConstraints.SOUTH;
	}

	public void appendTextArea(String str){
	    if(str != null){
        	str = str + newline;
 	        textArea.append(str);
	        textArea.setCaretPosition(textArea.getDocument().getLength());
	    }
	}
	
	public void publishUsers(ArrayList<String> users){
		textArea.selectAll();
		textArea.replaceSelection(null);
		if(users.size() >0)
			for(String s : users){
				textArea.append(s.toString() + "\n");
			}
	}


}
